import { Button, Col, Form, Input, Row, Select } from 'antd';
import { SearchRoleQuery } from '@/types/sys';
interface SearchRoleProps {
  onFinish: (values: SearchRoleQuery) => void;
  onAdd: (val: boolean) => void;
}

const SearchRole = forwardRef(({ onFinish, onAdd }: SearchRoleProps, ref) => {
  const [form] = Form.useForm();
  const handleFinish = (values: unknown) => {
    onFinish(values as SearchRoleQuery);
  };
  useImperativeHandle(ref, () => ({
    submit: () => {
      form.submit();
    },
  }));
  return (
    <Form form={form} layout="inline" onFinish={handleFinish}>
      <Row>
        <Col span={6}>
          <Form.Item label="角色名称" name="role_name">
            <Input placeholder="请输入角色名称" />
          </Form.Item>
        </Col>
        <Col span={6}>
          <Form.Item label="角色描述" name="remark">
            <Input placeholder="请输入角色名称" />
          </Form.Item>
        </Col>
        <Col span={6}>
          <Form.Item label="状态" name="status">
            <Select placeholder="请选择状态">
              <Select.Option value="1">启用</Select.Option>
              <Select.Option value="0">禁用</Select.Option>
            </Select>
          </Form.Item>
        </Col>
        <Col span={6}>
          <Form.Item>
            <Button type="primary" htmlType="submit">
              查询
            </Button>
            <Button
              style={{ marginLeft: 8 }}
              onClick={() => form.resetFields()}
            >
              重置
            </Button>
            <Button style={{ marginLeft: 8 }} onClick={() => onAdd(true)}>
              新增
            </Button>
          </Form.Item>
        </Col>
      </Row>
    </Form>
  );
});

export default SearchRole;
